package com.quanshu.shop.goods.custom;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.constraint.ConstraintLayout;
import android.support.v4.widget.NestedScrollView;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.bumptech.glide.Glide;
import com.quanshu.exchange.R;
import com.quanshu.exchange.support.config.Config;
import com.quanshu.exchange.support.net.BaseResponse;
import com.quanshu.exchange.support.net.core.BaseObserver;
import com.quanshu.exchange.support.net.core.BaseTransformer;
import com.quanshu.exchange.support.net.core.NetClient;
import com.quanshu.exchange.support.utils.AppUtils;
import com.quanshu.exchange.support.utils.RxViewHelper;
import com.quanshu.exchange.support.utils.ToastHelper;
import com.quanshu.exchange.ui.base.BaseActivity;
import com.quanshu.exchange.ui.base.MyApplication;
import com.quanshu.shop.base.data.BroadcastReciverAction;
import com.quanshu.shop.base.tool.BaseTool;
import com.quanshu.shop.goods.adapter.GoodsPropetyAdapter;
import com.quanshu.shop.goods.entity.CartBaseEntity;
import com.quanshu.shop.goods.entity.GoodPropertyPutEntity;
import com.quanshu.shop.goods.entity.GoodsInfoEntity;
import com.quanshu.shop.goods.entity.GoodsPropertyBaseEntity;
import com.quanshu.shop.goods.entity.GoodsPropertyEntity;
import com.quanshu.shop.goods.entity.GoodsPropetyChildEntity;
import com.quanshu.shop.goods.entity.MyCartEntity;
import com.quanshu.shop.goods.entity.SkuEntity;
import com.quanshu.shop.main.api.ShopMainIF;
import com.quanshu.shop.order.SubmitOrderActivity;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.quanshu.exchange.support.utils.LogUtil.TAG;

/**
 * 作者  李哲
 * 创建时间 2018/9/17
 * 邮箱 lizhetongliao@163.com
 * 说明
 **/
public class CartDialogSpecialWindow extends Dialog{

    @BindView(R.id.cart_dialog_img)
    ImageView cartDialogImg;
    @BindView(R.id.cart_dialog_txt_name)
    TextView cartDialogTxtName;
    @BindView(R.id.cart_dialog_txt_money)
    TextView cartDialogTxtMoney;
    @BindView(R.id.cart_dialog_rl)
    RecyclerView cartDialogRl;
    @BindView(R.id.cart_dialog_cl_rebate_title)
    TextView cartDialogClRebateTitle;
    @BindView(R.id.cart_dialog_cl_rebate)
    ConstraintLayout cartDialogClRebate;
    @BindView(R.id.cart_dialog_txt_payment_title)
    TextView cartDialogTxtPaymentTitle;
    @BindView(R.id.cart_dialog_rb1_payment)
    RadioButton cartDialogRb1Payment;
    @BindView(R.id.cart_dialog_rb2_payment)
    RadioButton cartDialogRb2Payment;
    @BindView(R.id.cart_dialog_rg_payment)
    RadioGroup cartDialogRgPayment;
    @BindView(R.id.cart_number_txt_title)
    TextView cartNumberTxtTitle;
    @BindView(R.id.cart_number_fl1)
    FrameLayout cartNumberFl1;
    @BindView(R.id.cart_number_fl2)
    FrameLayout cartNumberFl2;
    @BindView(R.id.cart_number_fl3)
    FrameLayout cartNumberFl3;
    @BindView(R.id.cart_dialog_cl_payment)
    ConstraintLayout cartDialogClPayment;
    @BindView(R.id.cart_dialog_fl_back)
    FrameLayout cartDialogFlBack;
    @BindView(R.id.cart_dialog_ok)
    TextView cartDialogOk;
    @BindView(R.id.cart_number_cl)
    ConstraintLayout cartNumberCl;
    @BindView(R.id.cart_dialog_cl_cb_rebate1)
    CheckBox cartDialogClCbRebate1;
    @BindView(R.id.cart_dialog_cl_txt_rebate1)
    TextView cartDialogClTxtRebate1;
    @BindView(R.id.cart_dialog_cl_view_rebate1)
    View cartDialogClViewRebate1;
    @BindView(R.id.cart_dialog_txt_tips)
    TextView cartDialogTxtTips;
    @BindView(R.id.cart_nestedScrollview)
    NestedScrollView cartNestedScrollview;
    @BindView(R.id.cart_dialog_cl_fl_rebate1)
    FrameLayout cartDialogClFlRebate1;
    @BindView(R.id.cart_dialog_txt_inventory)
    TextView cartDialogTxtInventory;
    @BindView(R.id.cart_dialog_txt_money1)
    TextView cartDialogTxtMoney1;
    @BindView(R.id.cart_dialog_fl_money)
    RelativeLayout cartDialogFlMoney;
    @BindView(R.id.cart_number_fl21)
    TextView cartNumberFl21;
    @BindView(R.id.cart_number_fl31)
    TextView cartNumberFl31;
    @BindView(R.id.cart_number_fl11)
    TextView cartNumberFl11;
    private Context mContext;
    private List<GoodsPropertyEntity> goodsPropertyEntityList;
    private GoodsPropetyAdapter goodsPropetyAdapter;
    private GoodsInfoEntity.DataEntity dataEntity;
    private boolean isBuy = false;
    private HashMap<String, GoodPropertyPutEntity> propertyHashMap;
    private int mInventory = 0;
    private int goodsNumber = 0;
    private SkuEntity skuEntity;
    private String buyAway = "0";
    private String goodTypeId;
    private int buyState;
    private int blockNumber = 0;//当前库存
    private List<CartBaseEntity> cartBaseEntityList;
    private CartBaseEntity cartBaseEntity;

    public CartDialogSpecialWindow(final Context context, GoodsInfoEntity.DataEntity dataEntity1) {
        super(context, R.style.CartDialogWindow);
        mContext = context;
        dataEntity = dataEntity1;
        cartBaseEntityList = new ArrayList<>();
        cartBaseEntity = new CartBaseEntity();
        MyCartEntity.GoodsListEntity goodsListEntity = new MyCartEntity.GoodsListEntity();
        cartBaseEntity.setGoodsListEntity(goodsListEntity);


    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_cart_special_window);
        ButterKnife.bind(this);
        setCancelable(false);//点击外部不可dismiss
        setCanceledOnTouchOutside(false);
        Window window = this.getWindow();
        window.setGravity(Gravity.BOTTOM);
        WindowManager.LayoutParams params = window.getAttributes();
        params.width = WindowManager.LayoutParams.MATCH_PARENT;
        params.height = BaseTool.getAndroiodScreenProperty(mContext) / 4 * 3;
        window.setAttributes(params);
        initView();
        initListener();
    }


    private void initView() {
        goodTypeId = dataEntity.getId();
        propertyHashMap = new HashMap<>();
        cartDialogTxtName.setText(dataEntity.getName());
        Glide.with(mContext).load(Config.URL_HOST_SHOP + dataEntity.getImg()).into(cartDialogImg);
        RxViewHelper.getInstance().clicks(cartDialogFlBack, aVoid ->
                dismiss()
        );
        RxViewHelper.getInstance().clicks(cartDialogOk, aVoid ->
                {
                    if (blockNumber == 0) {
                        ToastHelper.toast("库存不足");
                        return;
                    }
                    if (buyState == 0) {
                        addCart();
                    } else {
                        cartBaseEntity.getGoodsListEntity().setGoods_id(goodTypeId);
                        if (dataEntity.getSpec_array() != null && dataEntity.getSpec_array().size() > 0) {
                            cartBaseEntity.getGoodsListEntity().setSpec_array(JSON.toJSONString(dataEntity.getSpec_array()));
                            cartBaseEntity.getGoodsListEntity().setProduct_id(goodTypeId);
                        } else {
                            cartBaseEntity.getGoodsListEntity().setSpec_array("");
                        }
                        String isInn = cartDialogClCbRebate1.isChecked() ? "1" : "0";
                        cartBaseEntity.getGoodsListEntity().setIs_service(isInn);
                        cartBaseEntity.getGoodsListEntity().setPayment_options(buyAway);
                        cartBaseEntity.getGoodsListEntity().setCount(String.valueOf(goodsNumber));
                        cartBaseEntityList.add(cartBaseEntity);
                        Bundle bundle = new Bundle();
                        bundle.putString("order_state", "0");
                        bundle.putSerializable("order_data", (Serializable) cartBaseEntityList);
                        BaseTool.goActivity(mContext, SubmitOrderActivity.class, bundle);
                        //ToastHelper.toast("直接购买");
                    }
                }

        );
        cartDialogClFlRebate1.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                switch (motionEvent.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        cartDialogTxtTips.setVisibility(View.VISIBLE);
                        break;
                    case MotionEvent.ACTION_UP:
                        cartDialogTxtTips.setVisibility(View.INVISIBLE);
                        break;
                }
                return true;
            }
        });
        cartNestedScrollview.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
            @Override
            public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
                cartDialogTxtTips.setVisibility(View.INVISIBLE);
            }
        });
        cartDialogRl.setNestedScrollingEnabled(false);
        goodsPropertyEntityList = new ArrayList<>();
        if (dataEntity != null && dataEntity.getSpec_array() != null && dataEntity.getSpec_array().size() > 0) {
            for (int a = 0; a < dataEntity.getSpec_array().size(); a++) {
                GoodsPropertyEntity goodsPropertyEntity = new GoodsPropertyEntity();
                goodsPropertyEntity.setName(dataEntity.getSpec_array().get(a).getName());
                goodsPropertyEntity.setSpec_array(dataEntity.getSpec_array());
                List<GoodsPropetyChildEntity> goodsPropetyChildEntityList = new ArrayList();
                GoodPropertyPutEntity goodPropertyPutEntity = new GoodPropertyPutEntity();
                for (int b = 0; b < dataEntity.getSpec_array().get(a).getValue().size(); b++) {
                    GoodsPropetyChildEntity goodsPropetyChildEntity = new GoodsPropetyChildEntity();
                    goodsPropetyChildEntity.setName(dataEntity.getSpec_array().get(a).getValue().get(b));
                    if (b == 0) {
                        goodsPropetyChildEntity.setSelect(true);
                        goodPropertyPutEntity.setId(dataEntity.getSpec_array().get(a).getId());
                        goodPropertyPutEntity.setName(dataEntity.getSpec_array().get(a).getName());
                        goodPropertyPutEntity.setType(dataEntity.getSpec_array().get(a).getType());
                        goodPropertyPutEntity.setValue(dataEntity.getSpec_array().get(a).getValue().get(0));
                        goodPropertyPutEntity.setTip(dataEntity.getSpec_array().get(a).getValue().get(0));
                        goodPropertyPutEntity.setParentId(a);
                        goodPropertyPutEntity.setChildId(0);
                    } else {
                        goodsPropetyChildEntity.setSelect(false);
                    }
                    goodsPropetyChildEntityList.add(goodsPropetyChildEntity);
                }
                propertyHashMap.put(dataEntity.getSpec_array().get(a).getName(), goodPropertyPutEntity);
                goodsPropertyEntity.setStringList(goodsPropetyChildEntityList);
                goodsPropertyEntityList.add(goodsPropertyEntity);
            }
            goodsPropetyAdapter = new GoodsPropetyAdapter(mContext, goodsPropertyEntityList);
            goodsPropetyAdapter.setOndialogOnclickListener(new GoodsPropetyAdapter.OnGoodsDialogclickListenner() {
                @Override
                public void onclickPosition(int parentPosition, int childPosition) {
                    Log.d("点击", "onItemChildClick: ---" + parentPosition + "--------" + childPosition);
                    String name = goodsPropertyEntityList.get(parentPosition).getName();
                    Log.d("点击", "onItemChildClick: ---" + name);
                    if (propertyHashMap.get(name).getChildId() != childPosition) {
                        Log.d("执行", "onItemChildClick: ---点击内部");
                        goodsPropertyEntityList.get(parentPosition).getStringList().get(propertyHashMap.get(name).getChildId()).setSelect(false);
                        Log.d("执行", "onItemChildClick: ---点击内部" + propertyHashMap.get(name).getChildId());
                        goodsPropertyEntityList.get(parentPosition).getStringList().get(childPosition).setSelect(true);
                        Log.d("执行", "onItemChildClick: ---点击内部" + childPosition);
                        GoodPropertyPutEntity goodPropertyPutEntity = propertyHashMap.get(name);
                        goodPropertyPutEntity.setParentId(parentPosition);
                        goodPropertyPutEntity.setChildId(childPosition);
                        goodPropertyPutEntity.setName(goodsPropertyEntityList.get(parentPosition).getSpec_array().get(parentPosition).getName());
                        goodPropertyPutEntity.setId(goodsPropertyEntityList.get(parentPosition).getSpec_array().get(parentPosition).getId());
                        goodPropertyPutEntity.setType(goodsPropertyEntityList.get(parentPosition).getSpec_array().get(parentPosition).getType());
                        goodPropertyPutEntity.setValue(goodsPropertyEntityList.get(parentPosition).getSpec_array().get(parentPosition).getValue().get(childPosition));
                        goodPropertyPutEntity.setTip(goodsPropertyEntityList.get(parentPosition).getSpec_array().get(parentPosition).getValue().get(childPosition));
                        goodPropertyPutEntity.setParentId(parentPosition);
                        goodPropertyPutEntity.setChildId(childPosition);
                        propertyHashMap.remove(name);
                        propertyHashMap.put(name, goodPropertyPutEntity);
                    }
                    goodsPropetyAdapter.notifyDataSetChanged();
                    getSku();
                }
            });
            LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext);
            linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
            cartDialogRl.setLayoutManager(linearLayoutManager);
            cartDialogRl.setAdapter(goodsPropetyAdapter);
        } else {
            goodsNumber = 1;
            cartNumberFl3.setEnabled(false);
            cartNumberFl31.setEnabled(false);
            cartNumberFl1.setEnabled(true);
            cartNumberFl11.setEnabled(true);
            cartNumberFl21.setText("1");
            cartDialogOk.setEnabled(true);
            cartDialogTxtMoney.setText(dataEntity.getSell_price());
            cartDialogTxtInventory.setText("库存：" + dataEntity.getStore_nums());
            blockNumber = Integer.parseInt(dataEntity.getStore_nums());
            cartDialogTxtMoney1.setText(dataEntity.getNiu_score());
            sumMoney();
        }
        if (Integer.parseInt(dataEntity.getIs_integral()) == 0) {
            cartDialogRb2Payment.setVisibility(View.GONE);
        } else if (Integer.parseInt(dataEntity.getIs_integral()) == 1) {
            cartDialogRb2Payment.setVisibility(View.VISIBLE);
        }
    }

    private void initListener() {
        cartDialogClCbRebate1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b) {
                    //勾选大礼包
                    cartDialogRb1Payment.setChecked(true);
                }
                sumMoney();
            }
        });

        cartDialogRgPayment.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                switch (i) {
                    case R.id.cart_dialog_rb1_payment:
                        cartDialogTxtMoney.setVisibility(View.VISIBLE);
                        cartDialogTxtMoney1.setVisibility(View.GONE);
                        buyAway = "0";
                        break;
                    case R.id.cart_dialog_rb2_payment:
                        cartDialogTxtMoney.setVisibility(View.GONE);
                        cartDialogTxtMoney1.setVisibility(View.VISIBLE);
                        buyAway = "1";
                        cartDialogClCbRebate1.setChecked(false);
                        break;
                }
            }
        });
    }


    @OnClick(R.id.cart_number_fl3)
    void reduceGoodsNumber() {
        if (dataEntity.getSpec_array() != null) {
            if (goodsNumber <= 0) {
                cartNumberFl3.setEnabled(false);
                cartNumberFl31.setEnabled(false);

            } else {
                goodsNumber--;
                cartNumberFl1.setEnabled(true);
                cartNumberFl11.setEnabled(true);
                if (goodsNumber == 0) {
                    cartNumberFl3.setEnabled(false);
                    cartNumberFl31.setEnabled(false);
                    cartDialogOk.setEnabled(false);
                }
                cartNumberFl21.setText(goodsNumber + "");
            }
        } else {
            if (goodsNumber <= 1) {
                cartNumberFl3.setEnabled(false);
                cartNumberFl31.setEnabled(false);

            } else {
                goodsNumber--;
                cartNumberFl1.setEnabled(true);
                cartNumberFl11.setEnabled(true);
                if (goodsNumber == 1) {
                    cartNumberFl3.setEnabled(false);
                    cartNumberFl31.setEnabled(false);
                }
                cartNumberFl21.setText(goodsNumber + "");
            }
        }
        sumMoney();
    }

    @OnClick(R.id.cart_number_fl1)
    void plusGoodsNumber() {
        if (dataEntity.getSpec_array() != null) {
            if (goodsNumber >= Integer.parseInt(skuEntity.getStore_nums())) {
                cartNumberFl1.setEnabled(false);
                cartNumberFl11.setEnabled(false);
            } else {
                goodsNumber++;
                cartNumberFl31.setEnabled(true);
                cartNumberFl3.setEnabled(true);
                cartDialogOk.setEnabled(true);
                cartNumberFl21.setText(goodsNumber + "");
                if (goodsNumber == Integer.parseInt(skuEntity.getStore_nums())) {
                    cartNumberFl11.setEnabled(false);
                    cartNumberFl1.setEnabled(false);
                }
            }
        } else {
            if (goodsNumber >= Integer.parseInt(dataEntity.getStore_nums())) {
                cartNumberFl1.setEnabled(false);
                cartNumberFl11.setEnabled(false);
            } else {
                goodsNumber++;
                cartNumberFl31.setEnabled(true);
                cartNumberFl3.setEnabled(true);
                cartDialogOk.setEnabled(true);
                cartNumberFl21.setText(goodsNumber + "");
                if (goodsNumber == Integer.parseInt(dataEntity.getStore_nums())) {
                    cartNumberFl11.setEnabled(false);
                    cartNumberFl1.setEnabled(false);
                }
            }
        }
        sumMoney();
    }

    private void getSku() {
        List<GoodsPropertyBaseEntity> goodsPropertyBaseEntityList = new ArrayList<>();
        for (int a = 0; a < dataEntity.getSpec_array().size(); a++) {
            GoodPropertyPutEntity goodPropertyPutEntity = propertyHashMap.get(dataEntity.getSpec_array().get(a).getName());
            GoodsPropertyBaseEntity goodsPropertyBaseEntity = new GoodsPropertyBaseEntity();
            goodsPropertyBaseEntity.setId(goodPropertyPutEntity.getId());
            goodsPropertyBaseEntity.setType(goodPropertyPutEntity.getType());
            goodsPropertyBaseEntity.setValue(goodPropertyPutEntity.getValue());
            goodsPropertyBaseEntity.setName(goodPropertyPutEntity.getName());
            goodsPropertyBaseEntity.setTip(goodPropertyPutEntity.getTip());
            goodsPropertyBaseEntityList.add(goodsPropertyBaseEntity);
        }
//        for (Map.Entry<String, GoodPropertyPutEntity> entry : propertyHashMap.entrySet()) {
//            GoodPropertyPutEntity goodPropertyPutEntity = entry.getValue();
//            GoodsPropertyBaseEntity goodsPropertyBaseEntity = new GoodsPropertyBaseEntity();
//            goodsPropertyBaseEntity.setId(goodPropertyPutEntity.getId());
//            goodsPropertyBaseEntity.setType(goodPropertyPutEntity.getType());
//            goodsPropertyBaseEntity.setValue(goodPropertyPutEntity.getValue());
//            goodsPropertyBaseEntity.setName(goodPropertyPutEntity.getName());
//            goodsPropertyBaseEntity.setTip(goodPropertyPutEntity.getTip());
//            goodsPropertyBaseEntityList.add(goodsPropertyBaseEntity);
//        }
        String mProperty = JSON.toJSONString(goodsPropertyBaseEntityList);
        Log.d(TAG, "getSku: " + mProperty);
        NetClient.getInstance().getShopService(ShopMainIF.class).getSkuInfo(dataEntity.getId(), mProperty).compose(new BaseTransformer<>((BaseActivity) mContext)).subscribe(new BaseObserver<BaseResponse<SkuEntity>>() {
            @Override
            public void onFailure(Throwable e) {
                cartDialogTxtMoney.setText("¥ 0.00");
                cartDialogTxtInventory.setText("库存：0");
                blockNumber = 0;
                cartDialogTxtMoney1.setText("0.00");
                mInventory = 0;
                cartNumberFl1.setEnabled(false);
                cartNumberFl3.setEnabled(false);
                cartNumberFl11.setEnabled(false);
                cartNumberFl31.setEnabled(false);
                skuEntity = null;
                goodTypeId = dataEntity.getId();
                cartDialogOk.setEnabled(false);
            }

            @Override
            public void onSuccess(BaseResponse<SkuEntity> response) {
                Log.d(TAG, "onSuccess: -----" + response.getData());
                if (response.getData() != null) {
                    goodTypeId = response.getData().getId();
                    skuEntity = response.getData();
                    cartDialogTxtMoney.setText("¥ " + response.getData().getSell_price());
                    cartDialogTxtInventory.setText("库存：" + response.getData().store_nums);
                    blockNumber = Integer.parseInt(response.getData().store_nums);
                    mInventory = Integer.parseInt(response.getData().store_nums);
                    cartDialogTxtMoney1.setText(response.getData().getNiu_score());
                    if (goodsNumber == 0 && Integer.parseInt(skuEntity.getStore_nums()) > 0) {
                        Log.d(TAG, "onSuccess: -----123");
                        cartNumberFl3.setEnabled(false);
                        cartNumberFl1.setEnabled(true);
                        cartNumberFl31.setEnabled(false);
                        cartNumberFl11.setEnabled(true);
                        cartDialogOk.setEnabled(false);
                    } else if (goodsNumber > 0 && Integer.parseInt(skuEntity.getStore_nums()) > goodsNumber) {
                        cartNumberFl3.setEnabled(true);
                        cartNumberFl1.setEnabled(true);
                        cartNumberFl31.setEnabled(true);
                        cartNumberFl11.setEnabled(true);
                        cartDialogOk.setEnabled(true);
                    } else if (goodsNumber > 0 && Integer.parseInt(skuEntity.getStore_nums()) == goodsNumber) {
                        cartNumberFl3.setEnabled(true);
                        cartNumberFl1.setEnabled(false);
                        cartNumberFl31.setEnabled(true);
                        cartNumberFl11.setEnabled(false);
                        cartDialogOk.setEnabled(true);
                    } else if (goodsNumber > 0 && Integer.parseInt(skuEntity.getStore_nums()) <= goodsNumber) {
                        goodsNumber = Integer.parseInt(skuEntity.getStore_nums());
                        cartNumberFl3.setEnabled(true);
                        cartNumberFl1.setEnabled(false);
                        cartNumberFl31.setEnabled(true);
                        cartNumberFl11.setEnabled(false);
                        cartDialogOk.setEnabled(true);
                    }
                    sumMoney();
                }

            }
        });
    }

    //添加到购物车
    private void addCart() {
        String isInn = cartDialogClCbRebate1.isChecked() ? "1" : "0";
        String type = dataEntity.getSpec_array() == null || dataEntity.getSpec_array().size() <= 0 ? "goods" : "product";
        NetClient.getInstance().getShopService(ShopMainIF.class).addGoodsToCartInfo(AppUtils.getSignParams(goodTypeId, String.valueOf(goodsNumber), isInn, buyAway, MyApplication.getInstance().getCurrentUser().getId(), type), goodTypeId, String.valueOf(goodsNumber), isInn, buyAway, MyApplication.getInstance().getCurrentUser().getId(), type).compose(new BaseTransformer<>((BaseActivity) mContext)).subscribe(new BaseObserver<BaseResponse<String>>() {
            @Override
            public void onFailure(Throwable e) {

            }

            @Override
            public void onSuccess(BaseResponse<String> response) {
                ToastHelper.toast(response.getMsg());
                Intent intent = new Intent();
                intent.setAction(BroadcastReciverAction.UPDATE_MY_CART);
                mContext.sendBroadcast(intent);
                dismiss();
            }
        });
    }

    private void sumMoney() {
        BigDecimal bigDecimal;//计算现金
        BigDecimal bigDecimal1;//计算牛积分
        BigDecimal bigDecimalNumber;
        if (cartDialogClCbRebate1.isChecked()) {
            bigDecimalNumber = new BigDecimal(String.valueOf(goodsNumber * 2));
        } else {
            bigDecimalNumber = new BigDecimal(String.valueOf(goodsNumber));
        }
        if (dataEntity.getSpec_array() != null && dataEntity.getSpec_array().size() > 0) {
            if (skuEntity != null) {
                bigDecimal = new BigDecimal(skuEntity.getSell_price());//计算现金
                bigDecimal1 = new BigDecimal(skuEntity.getNiu_score());//计算牛积分
                double rmbResult = bigDecimal.multiply(bigDecimalNumber).doubleValue();
                double njfResult = bigDecimal1.multiply(bigDecimalNumber).doubleValue();
                cartDialogTxtMoney.setText("¥ " + String.valueOf(rmbResult));
                cartDialogTxtMoney1.setText(String.valueOf(njfResult));
            } else {
                cartDialogTxtMoney.setText("¥ 0.00");
                cartDialogTxtMoney1.setText("0.00");
            }
        } else {
            bigDecimal = new BigDecimal(dataEntity.getSell_price());//计算现金
            bigDecimal1 = new BigDecimal(dataEntity.getNiu_score());//计算牛积分
            double rmbResult = bigDecimal.multiply(bigDecimalNumber).doubleValue();
            double njfResult = bigDecimal1.multiply(bigDecimalNumber).doubleValue();
            cartDialogTxtMoney.setText("¥ " + String.valueOf(rmbResult));
            cartDialogTxtMoney1.setText(String.valueOf(njfResult));
        }


    }
}
